<template>
  <div class="query-list">
    <nanning-screen-search @on-input-search="onInputSearch" :searchValue="searchValue" :placeholderValue="placeholderValue" @on-click-input="onClickInput"></nanning-screen-search>
    <div class="query-list-content">
      <!-- <div class="query-list-content-title">共152条数据</div> -->
      <div class="swiper">
        <div v-for="(item, index) in dataList" :key="index" class="swiper-slide">
          <div :class="['query-list-content-item', activeCode === item.id ? 'active' : '']" @click="onChangeItem(item.id)">
            <div class="item-left">{{ item.name }}</div>
            <div class="item-right">
              <div>所属公司：{{ item.company }}</div>
              <div>联系方式：{{ item.phone }}</div>
            </div>
            <div class="img" :style="{ background: 'url(' + item.imgUrl + ')' }">空车</div>
          </div>
        </div>
        <screen-load-more :loadMoreVisible="loadMoreVisible" :loadMoreType="loadMoreType"></screen-load-more>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import Bus from 'utils/eventBus'
enum LoadMoreType {
  none = 'none',
  loading = 'loading'
}
@Component({
  name: 'query-list'
})
export default class QueryList extends Vue {
  private loadMoreVisible = false

  private loadMoreType: LoadMoreType = LoadMoreType.none

  private dataList: any = [
    {
      id: '1',
      name: '桂A56230',
      phone: '18300592204',
      company: '南宁公交有限公司',
      typeName: '售票员',
      imgUrl: require('assets/images/situational-awareness/kongche.png')
    },
    {
      id: '2',
      name: '桂A562Y0',
      phone: '18300589204',
      company: '南宁公交有限公司',
      typeName: '售票员',
      imgUrl: require('assets/images/situational-awareness/kongche.png')
    },
    {
      id: '3',
      name: '桂AU62Y0',
      phone: '18960589204',
      company: '南宁公交有限公司',
      typeName: '售票员',
      imgUrl: require('assets/images/situational-awareness/kongche.png')
    },
    {
      id: '4',
      name: '桂AU8920',
      phone: '18960582204',
      company: '南宁公交有限公司',
      typeName: '售票员',
      imgUrl: require('assets/images/situational-awareness/kongche.png')
    }
  ]

  private activeCode = '1'

  private searchValue = ''

  private placeholderValue = '请输入车辆'

  private onChangeItem(value: any) {
    this.activeCode = value
  }

  private onInputSearch(value: any) {
    this.searchValue = value
  }

  private onClickInput(value: any) {
    Bus.$emit('openCarSearchPop', value)
  }

  mounted() {
    this.onReachBottom()
  }

  created() {
    Bus.$on('onClickCarSearch', (value: any) => {
      console.log('实时车辆---右侧盒子', value)
    })
  }

  destroyed() {
    // @ts-ignore
    document.querySelector('.swiper').removeEventListener('scroll', (e: any) => {
      const { scrollHeight, scrollTop, clientHeight } = e.target
      if (clientHeight + scrollTop >= scrollHeight) {
        this.loadMoreVisible = true
      }
    })
  }

  onReachBottom() {
    // @ts-ignore
    document.querySelector('.swiper').addEventListener('scroll', (e: any) => {
      const { scrollHeight, scrollTop, clientHeight } = e.target
      if (clientHeight + scrollTop >= scrollHeight) {
        this.loadMoreVisible = true
      }
    })
  }
}
</script>

<style lang="scss" scoped>
.query-list {
  box-sizing: border-box;
  width: 100%;
  height: calc(100% - 50px);
  padding: 30px 20px 24px 22px;
  &-content {
    box-sizing: border-box;
    width: 100%;
    height: calc(100% - 42px);
    padding-top: 30px;
    &-title {
      box-sizing: border-box;
      width: 100%;
      height: 25px;
      line-height: 25px;
      text-align: left;
      font-size: 14px;
      font-family: 'PingFang Regular';
      color: rgba(255, 255, 255, 0.6);
      padding-left: 15px;
    }
    .swiper {
      box-sizing: border-box;
      width: 100%;
      height: calc(100% - 25px);
      overflow-y: auto;
      &::-webkit-scrollbar {
        /*滚动条整体样式*/
        width: 6px; /*高宽分别对应横竖滚动条的尺寸*/
        height: 1px;
      }
      &::-webkit-scrollbar-thumb {
        /*滚动条里面小方块*/
        border-radius: 10px;
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        background: #114da7;
      }
      &::-webkit-scrollbar-track {
        /*滚动条里面轨道*/
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        border-radius: 10px;
        background: #061836;
      }
      .swiper-slide {
        box-sizing: border-box;
        width: 100%;
        height: calc(100% / 8 - 7px);
        margin-bottom: 7px;
      }
      .query-list-content-item {
        position: relative;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        width: 100%;
        height: 100%;
        background: url('../../../../../assets/images/situational-awareness/car-right-bac.png') center no-repeat;
        background-size: 100% 100%;
        font-family: 'PingFang Regular';
        padding-left: 45px;
        .item-left {
          width: 20%;
          margin-right: 20px;
          font-size: 18px;
          color: rgba(255, 255, 255, 0.8);
        }
        .item-right {
          width: calc(80% - 20px);
          text-align: left;
          font-size: 16px;
          color: rgba(255, 255, 255, 0.8);
        }
        .img {
          background: url('../../../../../assets/images/situational-awareness/kongche.png') center no-repeat;
          position: absolute;
          right: 0%;
          top: 0%;
          width: 46px;
          height: 24px;
          text-align: center;
          line-height: 24px;
          font-size: 16px;
          color: rgba(255, 255, 255, 0.67);
        }
      }
      .active {
        background: url('../../../../../assets/images/situational-awareness/car-right-active-bac.png') center no-repeat;
        background-size: 100% 100%;
        .item-left {
          color: rgba(255, 255, 255, 1);
        }
        .item-right {
          color: rgba(255, 255, 255, 1);
        }
      }
      .swiper-scrollbar /deep/ .swiper-scrollbar-drag {
        background: rgba(16, 75, 164, 0) !important;
      }
    }
  }
}
</style>
